﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 原型模式深复制
{
    /// <summary>
    /// 简历类
    /// </summary>
    class Resume : ICloneable
    {
        string name;
        string sex;
        string age;

        WorkExperience work;

        public Resume(string name)
        {
            this.name = name;
            work = new WorkExperience(); //“简历类”实例化时 也实例化工作经历类
        }

        //克隆"引用对象"(work)的数据 
        private Resume(WorkExperience work)
        {
            this.work = (WorkExperience)work.Clone();
        }


        public void SetPersonalInfo(string sex, string age)
        {
            this.sex = sex;
            this.age = age;
        }
        public void SetWorkExperience(string timeArea, string company)
        {
            work.WorkData = timeArea;
            work.Company = company;
        }
        public void Display()
        {
            Console.WriteLine("{0} {1} {2}", name, sex, age);
            Console.WriteLine("工作经历：{0} {1}", work.WorkData, work.Company);
        }

        public object Clone()
        {
            //浅赋值
            return this.MemberwiseClone();//创建当前object的浅表副本
        }

        /// <summary>
        /// 深复制
        /// </summary>
        /// <returns></returns>
        public object Copy()
        {
            //深复制
            Resume obj = new Resume(this.work);   //调用私有的构造函数Resume
            obj.name = this.name;
            obj.sex = this.sex;
            obj.age = this.age;
            return obj;
        }
    }
}
